import request from '@/axios'
import type { ConfigItem, ConfigListResponse } from '../types'

export const getConfigList = (params: { key?: string; pageNum?: number; pageSize?: number }) => {
  return request.get<{ code: number; message: string; data: ConfigListResponse }>({
    url: '/config/list',
    params
  }).then(res => {
    return {
      code: res.code,
      message: res.data?.message || '',
      data: res.data
    }
  })
}

// 详情配置接口 - 修改为通过ID获取
export const getConfigDetail = (id: number) => {
  return request.get<{ code: number; message: string; data: ConfigItem }>({
    url: `/config/${id}`
  }).then(res => {
    return {
      code: res.code,
      message: res.data?.message || '',
      data: res.data
    }
  })
}

// 添加配置
export const addConfig = (data: any) => {
  return request.post({ url: '/config/create', data })
}

// 修改配置
export const editConfig = (id: number, data: any) => {
  return request.put({ url: '/config/update/' + id, data })
}

// 后台删除配置
export const deleteConfig = (id: number) => {
  return request.delete({ url: `/config/delete/${id}` })
}